﻿mui.init({
	swipeBack:false, //启用右滑关闭功能
	keyEventBind: {
		backbutton: true  //关闭back按键监听
	}
}); 
mui.plusReady(initSomething);

var userid;
function initSomething(){
	var self = plus.webview.currentWebview();
	var type = self.type;
	if(type&&"child"==type){
		$("#backBtn").show();
	}else{
		$("#backBtn").hide();
		common.utils.confirmLoginOut();
	}
	userid = common.utils.getUserId();
	initNotice();
}

//获取数据
function initNotice(){
	mui.ajax(ctx+"mobile/notice/getUserReceiveNotice?userid="+userid,{
		dataType:'json',//服务器返回json格式数据
		type:'post',//HTTP请求类型
		timeout:10000,//超时时间设置为10秒；	              
		success:function(data){
	       	if(data&&data.success){
	       		initNotSignHtml(data.data.notSignList);
	       		initHaveSignHtml(data.data.haveSignList);
	      	}else{
	      		alert('服务器异常链接失败!');
	      	}
		},
		error:function(xhr,type,errorThrown){
			alert('服务器异常链接失败!');
		}
	});
}

function initNotSignHtml(data){
	var html = '';
	$.each(data,function(m,n){
		html = html + '<li class="mui-table-view-cell animated fadeInRight " data-id="'+data[m].id+'" style="animation-delay: 0.'+m+'s;">';
		html = html + '<div class="mui-table">';
		html = html + 		'<div class="mui-table-cell mui-col-xs-9">';
		html = html + 			'<h4 class="mui-ellipsis">[未读]'+data[m].title+'</h4>';
		html = html + 			'<p class="mui-h6 mui-ellipsis">'+data[m].sub_title+'</p>';
		html = html + 		'</div>';
		html = html + 		'<div class="mui-table-cell mui-col-xs-3 mui-text-right">';
		html = html + 			'<span class="mui-h5" style="font-size:10px">'+data[m].publish_time+'<br/>'+'</span>';
		html = html + 		'</div>';
		html = html + '</div>';
		html = html + '</li>';
	});
	$("#container").append(html);
}
function initHaveSignHtml(data){
	
	var html = '';
	$.each(data,function(m,n){
		html = html + '<li class="mui-table-view-cell animated fadeInRight " data-id="'+data[m].id+'" style="animation-delay: 0.'+m+'s;">';
		html = html + '<div class="mui-table">';
		html = html + 		'<div class="mui-table-cell mui-col-xs-9">';
		html = html + 			'<h4 class="mui-ellipsis">[已读]'+data[m].title+'</h4>';
		html = html + 			'<p class="mui-h6 mui-ellipsis">'+data[m].sub_title+'</p>';
		html = html + 		'</div>';
		html = html + 		'<div class="mui-table-cell mui-col-xs-3 mui-text-right">';
		html = html + 			'<span class="mui-h5" style="font-size:10px">'+data[m].publish_time+'<br/>'+'</span>';
		html = html + 		'</div>';
		html = html + '</div>';
		html = html + '</li>';
	});
	$("#container2").append(html);
	$(".mui-table-view-cell").off("tap");
	$(".mui-table-view-cell").on("tap",function(){
		var id = $(this).attr("data-id");
		var view = plus.webview.create("viewNotice.html", "viewNotice.html", {},{"noticeid":id});
		//	显示新页面
		plus.webview.show(view, "slide-in-right", "350ms", function() {}, false);
	});

}
